package com.example.helloworld;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;

import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.widget.Toast;
import android.content.Context;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Date d = new Date();
		FileOutputStream f;
		try {
			f = openFileOutput("date.txt",Context.MODE_APPEND);
			ObjectOutputStream m = new ObjectOutputStream(f);
			
			m.writeObject(d);
			m.close();
			
			FileInputStream fr = openFileInput("date.txt");
			ObjectInputStream mr = new ObjectInputStream(fr);
			
			try {
				Date dr = (Date) mr.readObject();
				Log.d("Read", "read date:"+dr);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			mr.close();

		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}

